package com.shujia.homework1;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

public class MyMapper extends Mapper<LongWritable,Text,Text,Text> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        FileSplit fs = (FileSplit) context.getInputSplit();
        String fname = fs.getPath().getName();
        if(fname.startsWith("part")){
            String[] split = line.split("\t");
            String[] keys = split[0].split("-");
            context.write(new Text(keys[1]),new Text("#"+keys[0]+","+keys[1]+","+split[1]));

        }else if(fname.startsWith("city")){
            String[] split = line.split(",");
            context.write(new Text(split[0]),new Text("$"+split[0]+"-"+split[1]));
        }
    }
}
